home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / cat.3 / SplitList.3 < prev    next >
Text File  |  1995-07-25  |  15KB  |  264 lines

  1.  
  2.  
  3.  
  4.      TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt((((3333))))             TTTTccccllll (((( ))))             TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt((((3333))))
  5.  
  6.  
  7.  
  8.      _________________________________________________________________
  9.  
  10.      NNNNAAAAMMMMEEEE
  11.           Tcl_SplitList,          Tcl_Merge,          Tcl_ScanElement,
  12.           Tcl_ConvertElement - manipulate Tcl lists
  13.  
  14.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  15.           ####iiiinnnncccclllluuuuddddeeee <<<<ttttccccllll....hhhh>>>>
  16.  
  17.           int
  18.           TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt(_i_n_t_e_r_p, _l_i_s_t, _a_r_g_c_P_t_r, _a_r_g_v_P_t_r)
  19.  
  20.           char *
  21.           TTTTccccllll____MMMMeeeerrrrggggeeee(_a_r_g_c, _a_r_g_v)
  22.  
  23.           int
  24.           TTTTccccllll____SSSSccccaaaannnnEEEElllleeeemmmmeeeennnntttt(_s_r_c, _f_l_a_g_s_P_t_r)
  25.  
  26.           int
  27.           TTTTccccllll____CCCCoooonnnnvvvveeeerrrrttttEEEElllleeeemmmmeeeennnntttt(_s_r_c, _d_s_t, _f_l_a_g_s)
  28.  
  29.      AAAARRRRGGGGUUUUMMMMEEEENNNNTTTTSSSS
  30.           Tcl_Interp   *_i_n_t_e_r_p      (out)     Interpreter to  use  for
  31.                                               error reporting.
  32.  
  33.           char         *_l_i_s_t        (in)      Pointer to a string with
  34.                                               proper list structure.
  35.  
  36.           int          *_a_r_g_c_P_t_r     (out)     Filled in with number of
  37.                                               elements in _l_i_s_t.
  38.  
  39.           char         ***_a_r_g_v_P_t_r   (out)     *_a_r_g_v_P_t_r will be  filled
  40.                                               in  with  the address of
  41.                                               an array of pointers  to
  42.                                               the strings that are the
  43.                                               extracted  elements   of
  44.                                               _l_i_s_t.    There  will  be
  45.                                               *_a_r_g_c_P_t_r  valid  entries
  46.                                               in  the  array, followed
  47.                                               by a NULL entry.
  48.  
  49.           int          _a_r_g_c         (in)      Number  of  elements  in
  50.                                               _a_r_g_v.
  51.  
  52.           char         **_a_r_g_v       (in)      Array  of   strings   to
  53.                                               merge  together  into  a
  54.                                               single    list.     Each
  55.                                               string   will  become  a
  56.                                               separate element of  the
  57.                                               list.
  58.  
  59.           char         *_s_r_c         (in)      String that is to become
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 7/10/95)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt((((3333))))             TTTTccccllll (((( ))))             TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt((((3333))))
  71.  
  72.  
  73.  
  74.                                               an element of a list.
  75.  
  76.           int          *_f_l_a_g_s_P_t_r    (in)      Pointer to word to  fill
  77.                                               in    with   information
  78.                                               about _s_r_c.  The value of
  79.                                               *_f_l_a_g_s_P_t_r must be passed
  80.                                               to TTTTccccllll____CCCCoooonnnnvvvveeeerrrrttttEEEElllleeeemmmmeeeennnntttt.
  81.  
  82.           char         *_d_s_t         (in)      Place to copy  converted
  83.                                               list    element.    Must
  84.                                               contain           enough
  85.                                               characters    to    hold
  86.                                               converted string.
  87.  
  88.           int          _f_l_a_g_s        (in)      Information  about  _s_r_c.
  89.                                               Must  be  value returned
  90.                                               by  previous   call   to
  91.                                               TTTTccccllll____SSSSccccaaaannnnEEEElllleeeemmmmeeeennnntttt,
  92.                                               possibly   OR-ed    with
  93.                                               TTTTCCCCLLLL____DDDDOOOONNNNTTTT____UUUUSSSSEEEE____BBBBRRRRAAAACCCCEEEESSSS.
  94.      _________________________________________________________________
  95.  
  96.  
  97.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  98.           These procedures may be used to disassemble  and  reassemble
  99.           Tcl   lists.   TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt  breaks  a  list  up  into  its
  100.           constituent elements, returning an array of pointers to  the
  101.           elements  using  _a_r_g_c_P_t_r  and _a_r_g_v_P_t_r.  While extracting the
  102.           arguments, TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt obeys the usual rules for backslash
  103.           substitutions  and braces.  The area of memory pointed to by
  104.           *_a_r_g_v_P_t_r is dynamically allocated;  in addition to the array
  105.           of  pointers, it also holds copies of all the list elements.
  106.           It is the caller's responsibility to free  up  all  of  this
  107.           storage.    For   example,  suppose  that  you  have  called
  108.           TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt with the following code:
  109.  
  110.                int argc, code;
  111.                char *string;
  112.                char **argv;
  113.                ...
  114.                code = Tcl_SplitList(interp, string, &argc, &argv);
  115.           Then you should eventually free the storage with a call like
  116.           the following:
  117.  
  118.                free((char *) argv);
  119.           TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt normally returns TTTTCCCCLLLL____OOOOKKKK, which means the  list
  120.           was  successfully  parsed.   If  there was a syntax error in
  121.           _l_i_s_t, then TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR is  returned  and  _i_n_t_e_r_p->_r_e_s_u_l_t  will
  122.           point  to  an  error  message  describing  the  problem.  If
  123.           TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR is  returned  then  no  memory  is  allocated  and
  124.  
  125.  
  126.  
  127.      Page 2                                          (printed 7/10/95)
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.      TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt((((3333))))             TTTTccccllll (((( ))))             TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt((((3333))))
  135.  
  136.  
  137.  
  138.           *_a_r_g_v_P_t_r is not modified.
  139.  
  140.           TTTTccccllll____MMMMeeeerrrrggggeeee is the  inverse  of  TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt:   it  takes  a
  141.           collection of strings given by _a_r_g_c and _a_r_g_v and generates a
  142.           result string that has proper list  structure.   This  means
  143.           that commands like iiiinnnnddddeeeexxxx may be used to extract the original
  144.           elements again.  In addition, if the result of TTTTccccllll____MMMMeeeerrrrggggeeee  is
  145.           passed  to TTTTccccllll____EEEEvvvvaaaallll, it will be parsed into _a_r_g_c words whose
  146.           values will be the  same  as  the  _a_r_g_v  strings  passed  to
  147.           TTTTccccllll____MMMMeeeerrrrggggeeee.   TTTTccccllll____MMMMeeeerrrrggggeeee  will  modify  the list elements with
  148.           braces and/or backslashes in order  to  produce  proper  Tcl
  149.           list  structure.  The result string is dynamically allocated
  150.           using mmmmaaaalllllllloooocccc(((())));  the  caller  must  eventually  release  the
  151.           space using ffffrrrreeeeeeee(((()))).
  152.  
  153.           If the result of TTTTccccllll____MMMMeeeerrrrggggeeee is passed to  TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt,  the
  154.           elements  returned  by  TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt  will  be identical to
  155.           those passed into TTTTccccllll____MMMMeeeerrrrggggeeee.  However, the converse  is  not
  156.           true:   if  TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt  is passed a given string, and the
  157.           resulting  _a_r_g_c  and  _a_r_g_v  are  passed  to  TTTTccccllll____MMMMeeeerrrrggggeeee,  the
  158.           resulting  string may not be the same as the original string
  159.           passed to TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt.  This is because TTTTccccllll____MMMMeeeerrrrggggeeee may  use
  160.           backslashes and braces differently than the original string.
  161.  
  162.           TTTTccccllll____SSSSccccaaaannnnEEEElllleeeemmmmeeeennnntttt and TTTTccccllll____CCCCoooonnnnvvvveeeerrrrttttEEEElllleeeemmmmeeeennnntttt  are  the  procedures
  163.           that  do all of the real work of TTTTccccllll____MMMMeeeerrrrggggeeee.  TTTTccccllll____SSSSccccaaaannnnEEEElllleeeemmmmeeeennnntttt
  164.           scans its _s_r_c argument and determines how to use backslashes
  165.           and braces when converting it to a list element.  It returns
  166.           an overestimate of the  number  of  characters  required  to
  167.           represent  _s_r_c  as a list element, and it stores information
  168.           in *_f_l_a_g_s_P_t_r that is needed by TTTTccccllll____CCCCoooonnnnvvvveeeerrrrttttEEEElllleeeemmmmeeeennnntttt.
  169.  
  170.           TTTTccccllll____CCCCoooonnnnvvvveeeerrrrttttEEEElllleeeemmmmeeeennnntttt   is    a    companion    procedure    to
  171.           TTTTccccllll____SSSSccccaaaannnnEEEElllleeeemmmmeeeennnntttt.   It  does  the actual work of converting a
  172.           string to a list element.  Its _f_l_a_g_s argument  must  be  the
  173.           same    as    the   value   returned   by   TTTTccccllll____SSSSccccaaaannnnEEEElllleeeemmmmeeeennnntttt.
  174.           TTTTccccllll____CCCCoooonnnnvvvveeeerrrrttttEEEElllleeeemmmmeeeennnntttt writes a proper list  element  to  memory
  175.           starting  at *_d_s_t and returns a count of the total number of
  176.           characters written, which will be no more  than  the  result
  177.           returned  by TTTTccccllll____SSSSccccaaaannnnEEEElllleeeemmmmeeeennnntttt.  TTTTccccllll____CCCCoooonnnnvvvveeeerrrrttttEEEElllleeeemmmmeeeennnntttt writes out
  178.           only the actual list element without any leading or trailing
  179.           spaces:  it  is  up  to the caller to include spaces between
  180.           adjacent list elements.
  181.  
  182.           TTTTccccllll____CCCCoooonnnnvvvveeeerrrrttttEEEElllleeeemmmmeeeennnntttt uses one of two different  approaches  to
  183.           handle the special characters in _s_r_c.  Wherever possible, it
  184.           handles special characters by surrounding  the  string  with
  185.           braces.   This  produces  clean-looking output, but can't be
  186.           used in some situations, such as when _s_r_c contains unmatched
  187.           braces.   In  these  situations,  TTTTccccllll____CCCCoooonnnnvvvveeeerrrrttttEEEElllleeeemmmmeeeennnntttt handles
  188.           special characters by  generating  backslash  sequences  for
  189.           them.   The  caller may insist on the second approach by OR-
  190.  
  191.  
  192.  
  193.      Page 3                                          (printed 7/10/95)
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.      TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt((((3333))))             TTTTccccllll (((( ))))             TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt((((3333))))
  201.  
  202.  
  203.  
  204.           ing  the  flag  value  returned  by   TTTTccccllll____SSSSccccaaaannnnEEEElllleeeemmmmeeeennnntttt   with
  205.           TTTTCCCCLLLL____DDDDOOOONNNNTTTT____UUUUSSSSEEEE____BBBBRRRRAAAACCCCEEEESSSS.   Although  this will produce an uglier
  206.           result, it is useful in some  special  situations,  such  as
  207.           when  TTTTccccllll____CCCCoooonnnnvvvveeeerrrrttttEEEElllleeeemmmmeeeennnntttt is being used to generate a portion
  208.           of an argument for a Tcl command.  In this case, surrounding
  209.           _s_r_c  with  curly  braces  would  cause the command not to be
  210.           parsed correctly.
  211.  
  212.  
  213.      KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS
  214.           backslash, convert, element, list, merge, split, strings
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.      Page 4                                          (printed 7/10/95)
  260.  
  261.  
  262.  
  263.